﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ELMWCFServiceClass.ELMWCF;

namespace SettingModule.Views.FieldSettingView
{
    public partial class FieldSettingView : UserControl,IFieldSettingView
    {
        public FieldSettingView()
        {
            InitializeComponent();
            
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            
            Button btn = (Button)sender;
            Guid id = new Guid(btn.Tag.ToString());
            ((IFieldSettingPresentationModel)DataContext).Delete(id);
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            CW_FieldAdd addView = new CW_FieldAdd((IFieldSettingPresentationModel)DataContext);
            addView.Show();
        }

        #region IFieldSettingView Members

        public void SetModel(IFieldSettingPresentationModel model)
        {
            this.DataContext =this.model= model;
        }
        private IFieldSettingPresentationModel model;
        #endregion

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cbGroup.SelectedIndex != -1)
            {

                displayDetailByGroup();
            }
            else
            {
                model.SelectedGroupId = -1;
                model.SelectedGroup();
            }
        }

        private void displayDetailByGroup()
        {
            t_FieldGroup group = (t_FieldGroup)cbGroup.SelectedItem;
            model.SelectedGroupId = group.FieldGroupId;
            model.SelectedGroup();
        }

        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            cbGroup.Visibility = Visibility.Collapsed;
            model.SelectedGroupId = -1;
            model.SelectedGroup();
        }

        private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            cbGroup.Visibility = Visibility.Visible;
            cbGroup.SelectedIndex = -1;
        }
    }
}
